from apscheduler.schedulers.background import BackgroundScheduler

scheduler = None


def init_scheduler():
    print("初始化定时任务执行器")
    global scheduler
    if scheduler is None:
        scheduler = BackgroundScheduler()
        scheduler.start()


def get_scheduler():
    if scheduler is None:
        init_scheduler()
    return scheduler


def shutdown():
    print("关闭定时任务执行器")
    global scheduler
    if scheduler:
        scheduler.shutdown()
        scheduler = None